<html lang="zh-CN"><head><meta charset="UTF-8"><style>.nodata  main {width:1000px;margin: auto;}</style></head><body class="nodata " style=""><div class="main_father clearfix d-flex justify-content-center " style="height:100%;"> <div class="container clearfix " id="mainBox"><main><div class="blog-content-box">
<div class="article-header-box">
<div class="article-header">
<div class="article-title-box">
<h1 class="title-article" id="articleContentId">(C卷,100分)- 开源项目热度榜单（Java & JS & Python & C）</h1>
</div>
</div>
</div>
<div id="blogHuaweiyunAdvert"></div>

        <div id="article_content" class="article_content clearfix">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-044f2cf1dc.css">
                <div id="content_views" class="htmledit_views">
                    <h4 id="main-toc">题目描述</h4> 
<p>某个开源社区希望将最近热度比较高的开源项目出一个榜单&#xff0c;推荐给社区里面的开发者。</p> 
<p>对于每个开源项目&#xff0c;开发者可以进行关注&#xff08;watch&#xff09;、收藏&#xff08;star&#xff09;、fork、提issue、提交合并请求&#xff08;MR&#xff09;等。</p> 
<p>数据库里面统计了每个开源项目关注、收藏、fork、issue、MR的数量&#xff0c;开源项目的热度根据这5个维度的加权求和进行排序。</p> 
<blockquote> 
 <p>H &#61; W(watch) x #watch &#43; W(star) x #star &#43; W(fork) x #fork &#43; W(issue) x #issue &#43; W(mr) x #mr</p> 
</blockquote> 
<ul><li>H 表示热度值</li><li>W(watch)、W(star)、W(fork)、W(issue)、W(mr) 分别表示5个统计维度的权重</li><li>#watch、#star、#fork、#issue、#mr 分别表示5个统计维度的统计值</li></ul> 
<p>榜单按照热度值降序排序&#xff0c;对于热度值相等的&#xff0c;按照项目名字转换为全小写字母后的字典序排序&#xff08;&#39;a&#39;,&#39;b&#39;,&#39;c&#39;,...,&#39;x&#39;,&#39;y&#39;,&#39;z&#39;&#xff09;。</p> 
<p></p> 
<h4 id="%E8%BE%93%E5%85%A5%E6%8F%8F%E8%BF%B0">输入描述</h4> 
<p>第一行输入为N&#xff0c;表示开源项目的个数&#xff0c;0 &#xff1c; N &#xff1c;100。</p> 
<p>第二行输入为权重值列表&#xff0c;一共 5 个整型值&#xff0c;分别对应关注、收藏、fork、issue、MR的权重&#xff0c;权重取值 0 &lt; W ≤ 50。</p> 
<p>第三行开始接下来的 N 行为开源项目的统计维度&#xff0c;每一行的格式为&#xff1a;</p> 
<blockquote> 
 <p>name nr_watch nr_start nr_fork nr_issue nr_mr</p> 
</blockquote> 
<p>其中 name 为开源项目的名字&#xff0c;由英文字母组成&#xff0c;长度 ≤ 50&#xff0c;其余 5 个整型值分别为该开源项目关注、收藏、fork、issue、MR的数量&#xff0c;数量取值 0 &lt; nr ≤ 1000。</p> 
<p></p> 
<h4 id="%E8%BE%93%E5%87%BA%E6%8F%8F%E8%BF%B0">输出描述</h4> 
<p>按照热度降序&#xff0c;输出开源项目的名字&#xff0c;对于热度值相等的&#xff0c;按照项目名字转换为全小写后的字典序排序&#xff08;&#39;a&#39; &gt; &#39;b&#39; &gt; &#39;c&#39; &gt; ... &gt; &#39;x&#39; &gt; &#39;y&#39; &gt; &#39;z&#39;&#xff09;。</p> 
<p></p> 
<h4 id="%E7%94%A8%E4%BE%8B">用例</h4> 
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;"><tbody><tr><td style="width:86px;">输入</td><td style="width:412px;">4<br /> 8 6 2 8 6<br /> camila 66 70 46 158 80<br /> victoria 94 76 86 189 211<br /> anthony 29 17 83 21 48<br /> emily 53 97 1 19 218</td></tr><tr><td style="width:86px;">输出</td><td style="width:412px;">victoria<br /> camila<br /> emily<br /> anthony</td></tr><tr><td style="width:86px;">说明</td><td style="width:412px;"> <p>排序热度值计算&#xff1a;</p> <p>camila&#xff1a;66*8 &#43; 70*6 &#43; 46*2 &#43; 158*8 &#43; 80*6 &#61; 2784</p> <p>victoria: 94*8 &#43; 76*6 &#43; 86*2 &#43; 189*8 &#43; 211*6 &#61; 4158</p> <p>anthony: 29*8 &#43; 17*6 &#43; 83*2 &#43; 21*8 &#43; 48*6 &#61; 956</p> <p>emily: 53*8 &#43; 97*6 &#43; 1*2 &#43; 19*8 &#43; 218*6 &#61; 2468</p> </td></tr></tbody></table> 
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;"><tbody><tr><td style="width:88px;">输入</td><td style="width:410px;">5<br /> 5 6 6 1 2<br /> camila 13 88 46 26 169<br /> grace 64 38 87 23 103<br /> lucas 91 79 98 154 79<br /> leo 29 27 36 43 178<br /> ava 29 27 36 43 178</td></tr><tr><td style="width:88px;">输出</td><td style="width:410px;">lucas<br /> grace<br /> camila<br /> ava<br /> leo</td></tr><tr><td style="width:88px;">说明</td><td style="width:410px;"> <p>排序热度值计算&#xff1a;</p> <p>camila: 13*5 &#43; 88*6 &#43; 46*6 &#43; 26*1 &#43; 169*2 &#61; 1233</p> <p>grace: 64*5 &#43; 38*6 &#43; 87*6 &#43; 23*1 &#43; 103*2 &#61; 1299</p> <p>lucas: 91*5 &#43; 79*6 &#43; 98*6 &#43; 154*1 &#43; 79*2 &#61; 1829</p> <p>leo: 29*5 &#43; 27*6 &#43; 36*6 &#43; 43*1 &#43; 178*2 &#61; 922</p> <p>ava: 29*5 &#43; 27*6 &#43; 36*6 &#43; 43*1 &#43; 178*2 &#61; 922</p> </td></tr></tbody></table> 
<p></p> 
<p></p> 
<h4 id="%E9%A2%98%E7%9B%AE%E8%A7%A3%E6%9E%90">题目解析</h4> 
<p>简单的多条件排序题。</p> 
<p>具体逻辑请看代码实现。</p> 
<p></p> 
<h4 id="%E7%AE%97%E6%B3%95%E6%BA%90%E7%A0%81">JavaScript算法源码</h4> 
<pre><code class="language-javascript">const rl &#61; require(&#34;readline&#34;).createInterface({ input: process.stdin });
var iter &#61; rl[Symbol.asyncIterator]();
const readline &#61; async () &#61;&gt; (await iter.next()).value;

void (async function () {
  class Project {
    constructor(name, hot) {
      this.name &#61; name;
      this.hot &#61; hot;
    }
  }

  const n &#61; parseInt(await readline());

  const weights &#61; (await readline()).split(&#34; &#34;).map(Number);

  const projects &#61; [];
  for (let i &#61; 0; i &lt; n; i&#43;&#43;) {
    const tmp &#61; (await readline()).split(&#34; &#34;);

    const name &#61; tmp.shift();

    let hot &#61; 0;
    tmp.map(Number);
    for (let j &#61; 0; j &lt; 5; j&#43;&#43;) {
      hot &#43;&#61; tmp[j] * weights[j];
    }

    projects.push(new Project(name, hot));
  }

  projects
    .sort((a, b) &#61;&gt;
      a.hot !&#61; b.hot ? b.hot - a.hot : strcmp(a.name.toLowerCase(), b.name.toLowerCase())
    )
    .forEach((p) &#61;&gt; console.log(p.name));
})();

function strcmp(a, b) {
  if (a &#61;&#61; b) {
    return 0;
  } else if (a &gt; b) {
    return 1;
  } else {
    return -1;
  }
}
</code></pre> 
<p></p> 
<h4 id="Java%E7%AE%97%E6%B3%95%E6%BA%90%E7%A0%81">Java算法源码</h4> 
<pre><code class="language-java">import java.util.Arrays;
import java.util.Scanner;

public class Main {
  static class Project {
    String name;
    int hot;

    public Project(String name, int hot) {
      this.name &#61; name;
      this.hot &#61; hot;
    }
  }

  public static void main(String[] args) {
    Scanner sc &#61; new Scanner(System.in);

    int n &#61; sc.nextInt();

    int[] weights &#61; new int[5];
    for (int i &#61; 0; i &lt; 5; i&#43;&#43;) {
      weights[i] &#61; sc.nextInt();
    }

    Project[] projects &#61; new Project[n];

    for (int i &#61; 0; i &lt; n; i&#43;&#43;) {
      String name &#61; sc.next();

      int hot &#61; 0;
      for (int j &#61; 0; j &lt; 5; j&#43;&#43;) {
        hot &#43;&#61; sc.nextInt() * weights[j];
      }

      projects[i] &#61; new Project(name, hot);
    }

    Arrays.sort(
        projects,
        (a, b) -&gt;
            a.hot !&#61; b.hot ? b.hot - a.hot : a.name.toLowerCase().compareTo(b.name.toLowerCase()));

    for (Project project : projects) {
      System.out.println(project.name);
    }
  }
}
</code></pre> 
<p></p> 
<h4 id="Python%E7%AE%97%E6%B3%95%E6%BA%90%E7%A0%81">Python算法源码</h4> 
<pre><code class="language-python">class Project:
    def __init__(self, name, hot):
        self.name &#61; name
        self.hot &#61; hot


# 输入获取
n &#61; int(input())

weights &#61; list(map(int, input().split()))

projects &#61; []
for _ in range(n):
    tmp &#61; input().split()

    name &#61; tmp.pop(0)

    statistics &#61; list(map(int, tmp))

    hot &#61; 0
    for i in range(5):
        hot &#43;&#61; statistics[i] * weights[i]

    projects.append(Project(name, hot))

projects.sort(key&#61;lambda x: (-x.hot, x.name.lower()))

for p in projects:
    print(p.name)
</code></pre> 
<p></p> 
<h4 id="C%E7%AE%97%E6%B3%95%E6%BA%90%E7%A0%81" style="background-color:transparent;">C算法源码</h4> 
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

#define MAX_NAME_LEN 51

typedef struct {
    char name[MAX_NAME_LEN];
    int hot;
} Project;

Project *new_Project(char *name, int hot) {
    Project *p &#61; (Project *) malloc(sizeof(Project));
    strcpy(p-&gt;name, name);
    p-&gt;hot &#61; hot;
    return p;
}

char *lower(char *s) {
    char *res &#61; (char *) calloc(MAX_NAME_LEN, sizeof(char));
    strcpy(res, s);

    int diff &#61; &#39;a&#39; - &#39;A&#39;;

    int i &#61; 0;
    while (res[i] !&#61; &#39;\0&#39;) {
        if (res[i] &gt;&#61; &#39;A&#39; &amp;&amp; res[i] &lt;&#61; &#39;Z&#39;) {
            res[i] &#61; (char) (res[i] &#43; diff);
        }
        i&#43;&#43;;
    }

    return res;
}

int cmp(const void *a, const void *b) {
    Project *A &#61; *((Project **) a);
    Project *B &#61; *((Project **) b);

    if (A-&gt;hot !&#61; B-&gt;hot) {
        return B-&gt;hot - A-&gt;hot;
    } else {
        return strcmp(lower(A-&gt;name), lower(B-&gt;name));
    }
}

int main() {
    int n;
    scanf(&#34;%d&#34;, &amp;n);

    int weights[5];
    for (int i &#61; 0; i &lt; 5; i&#43;&#43;) {
        scanf(&#34;%d&#34;, &amp;weights[i]);
    }

    Project *ps[n];

    for (int i &#61; 0; i &lt; n; i&#43;&#43;) {
        char name[MAX_NAME_LEN];
        scanf(&#34;%s&#34;, name);

        int hot &#61; 0;
        for (int j &#61; 0; j &lt; 5; j&#43;&#43;) {
            int val;
            scanf(&#34;%d&#34;, &amp;val);

            hot &#43;&#61; val * weights[j];
        }

        ps[i] &#61; new_Project(name, hot);
    }

    qsort(ps, n, sizeof(Project *), cmp);

    for (int i &#61; 0; i &lt; n; i&#43;&#43;) {
        puts(ps[i]-&gt;name);
    }

    return 0;
}</code></pre> 
<p></p>
                </div>
        </div>
        <div id="treeSkill"></div>
        <div id="blogExtensionBox" style="width:400px;margin:auto;margin-top:12px" class="blog-extension-box"></div>
    <script>
  $(function() {
    setTimeout(function () {
      var mathcodeList = document.querySelectorAll('.htmledit_views img.mathcode');
      if (mathcodeList.length > 0) {
        for (let i = 0; i < mathcodeList.length; i++) {
          if (mathcodeList[i].naturalWidth === 0 || mathcodeList[i].naturalHeight === 0) {
            var alt = mathcodeList[i].alt;
            alt = '\\(' + alt + '\\)';
            var curSpan = $('<span class="img-codecogs"></span>');
            curSpan.text(alt);
            $(mathcodeList[i]).before(curSpan);
            $(mathcodeList[i]).remove();
          }
        }
        MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
      }
    }, 1000)
  });
</script>
</div></html>